In [1]:
%load_ext autoreload
%autoreload 0
%autoreload 2
In [2]:
import sys, os
import numpy as np
import matplotlib.pyplot as plt

# Import the aims module
from soma import aims
# the brainplot package
import colorado as cld

print(sys.version)
3.6.9 (default, Jan 26 2021, 15:33:00) 
[GCC 8.4.0]

Anatomist snapshot

In [3]:
%%capture 
# The previous magic caputres this cell output (namely Anatomist logs)

# Import anatomist and set the environment to use it here
import anatomist.api as anatomist
os.environ["QT_API"] = "pyqt5"
%gui qt

# create an Anatomist session and capture input (so it does not appear here)
a = anatomist.Anatomist();
In [4]:
# load data (the SliceableObject)
t1mri = a.loadObject("data/subject01.nii")

# create an Axial window in anatomist
w = a.createWindow("Axial", geometry=[1200, 350, 500, 500])
t1mri.addInWindows(w)

# get a snapshot from anatomist
%matplotlib inline
img = cld.anatomist_snatpshot(w)
plt.imshow(img);
In [5]:
## View meshes
lwhite = a.loadObject("data/subject01_Lwhite.mesh")
rwhite = a.loadObject("data/subject01_Rwhite.mesh")
w3d = a.createWindow("3D")
w3d.addObjects([lwhite, rwhite])

plt.imshow(cld.anatomist_snatpshot(w3d))
Out[5]:
<matplotlib.image.AxesImage at 0x7f42772bdef0>

Meshes

In [3]:
meshR = aims.read('data/subject01_Rhemi.mesh')
meshL = aims.read('data/subject01_Lhemi.mesh')
cld.draw([meshL, meshR])

Buckets

In [2]:
bucket_map = aims.read('data/LAbby_New.bck')
# aims.read returns a bucketMap object, which is a list of buckets
# it can be plot as is or by indexing one of the buckets
bucket = bucket_map[0]
cld.draw(bucket)

Bucket as mesh

In [3]:
# for higher customization of the mesh calculation use cld.aims_tools.bucket_to_mesh()
cld.draw_as_mesh(bucket)
In [4]:
# play with the parameters
cld.draw_as_mesh(bucket,
                 gaussian_blur_FWWM=1, # apply a gaussian blur
                 threshold_quantile=0.2 # threshold a portion of voxels
                )

Volumes

In [5]:
vol = aims.read('data/subject01.nii')
cld.draw(vol,
         downsample=2,     # downsample the voxels in the volume
         max_points=5000,  # number of randomly sampled points to plot (low => fast)
         th_min=950,       # voxels below this value will not be plotted
         th_max=1000       # voxels above this value will not be plotted
)

Volume as mesh

In [6]:
from colorado.misc import sphere

# get a spherical object
n = 20 # size of the volume side
vol = sphere(n)

mesh = cld.aims_tools.volume_to_mesh(vol)
cld.draw([vol,mesh], shift=(n*1.1,0,0))
In [8]:
# in one line
cld.draw_as_mesh(vol)
In [ ]: